/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.cakerun.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.continew.admin.cakerun.model.req.GeneralReq;
import top.continew.admin.cakerun.model.resp.GeneralCountResp;
import top.continew.admin.cakerun.model.resp.GeneralDailyResp;
import top.continew.admin.cakerun.model.resp.GeneralProjectResp;
import top.continew.admin.cakerun.service.BoardService;
import top.continew.starter.excel.util.ExcelUtils;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;

import java.util.List;

@Tag(name = "看板数据")
@RestController
@RequestMapping("/cakerun/board")
@RequiredArgsConstructor
public class BoardController {

    private final BoardService boardService;

    /**
     * 通用看板统计数据
     *
     * @param req       查询条件
     * @param pageQuery 分页条件
     * @return 分页数据
     */
    @GetMapping("generalCount")
    public PageResp<GeneralCountResp> generalCountPage(GeneralReq req, PageQuery pageQuery) {
        return this.boardService.generalCountPage(req, pageQuery);
    }

    @GetMapping("generalCountExprot")
    public void generalCountExprot(GeneralReq req, HttpServletResponse response) {
        List<GeneralCountResp> generalCount = this.boardService.generalCount(req);
        ExcelUtils.export(generalCount, "门店统计看板", GeneralCountResp.class, response);
    }

    /**
     * 通用看板每日数据（不进行统计）
     *
     * @param req       查询条件
     * @param pageQuery 分页条件
     * @return 分页数据
     */
    @GetMapping("generalDaily")
    public PageResp<GeneralDailyResp> generalDailyPage(GeneralReq req, PageQuery pageQuery) {
        return this.boardService.generalDailyPage(req, pageQuery);
    }

    @GetMapping("generalDailyExport")
    public void generalDailyExport(GeneralReq req, HttpServletResponse response) {
        List<GeneralDailyResp> generalDaily = this.boardService.generalDaily(req);
        ExcelUtils.export(generalDaily, "门店每日看板", GeneralDailyResp.class, response);
    }

    /**
     * 通用看板每日数据（不进行统计）
     *
     * @param req       查询条件
     * @param pageQuery 分页条件
     * @return 分页数据
     */
    @GetMapping("generalProject")
    public PageResp<GeneralProjectResp> generalProjectPage(GeneralReq req, PageQuery pageQuery) {
        return this.boardService.generalProjectPage(req, pageQuery);
    }

    @GetMapping("generalProjectExport")
    public void generalProjectExport(GeneralReq req, HttpServletResponse response) {
        List<GeneralProjectResp> generalProjectResps = this.boardService.generalProject(req);
        ExcelUtils.export(generalProjectResps, "项目看板", GeneralProjectResp.class, response);
    }
}
